package com.lyz.dataStructure.algorithm.beike2020;/**
 * @Author:759057893@qq.com Lyz
 * @Date: ${Date} 20:12
 * @Description:
 **/

import java.util.ArrayList;
import java.util.Scanner;

/**
 *@Author:759057893@qq.com Lyz
 *@Date: 2019/8/10 20:12
 *@Description:
 **/
public class Main2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N= sc.nextInt();
        int[] arr = new int[N];
        for(int i =0;i<arr.length;i++){
            arr[i] = sc.nextInt();
        }
        System.out.println(shu(arr));
    }

    public static int shu(int[] arr){
       int[] nums = new int[arr.length];
       int size = 0;
       for(int x:arr){
           int i =0,j=size;
           while (i!=j){
               int y =(i+j)/2;
               if(nums[y]<x){
                   i=y+1;
               }else {
                   j =y;
               }
           }
           nums[i] = x;
           if(i ==size){
               ++size;
           }
       }
       return size;
    }
}
